home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / wgt / wgttut2 / gshade2.c < prev    next >
C/C++ Source or Header  |  1994-10-13  |  1KB  |  56 lines

  1. #include "wgtgfx.h"
  2. #include <time.h>
  3.  
  4.  
  5. void shadedline (int x1, int firstcolor, int x2, int lastcolor, int y)
  6. {
  7. int length;
  8. int numcolors;
  9. int colorvalue;
  10. int step;
  11. int x;
  12. unsigned char far * dest;   /* Ptr to the screen */
  13.  
  14.  length = x2 - x1 + 1;
  15.  if (length > 0)
  16.  {
  17.   numcolors = lastcolor - firstcolor + 1;
  18.  
  19.   colorvalue = firstcolor << 8;
  20.   step = ((long)numcolors << 8) / (long)length;
  21.  
  22.   dest = abuf + y * 320 + x1;
  23.   /* Make a pointer to the first pixel */
  24.  
  25.   for (x = x1; x <= x2; x++)
  26.     {
  27.      *dest++ = colorvalue >> 8;
  28.      /* Draw the pixel and move to the next location in memory */
  29.  
  30.      colorvalue += step;
  31.     }
  32.  }
  33. }
  34.  
  35. void main (void)
  36. {
  37. int i;
  38. unsigned char col;
  39.  
  40.  setvga256 ();
  41.  
  42.  do {
  43.  col = rand () % 256;  /* Pick a random color for the right endpoint */
  44.                /* This will let us see how fast the screen is
  45.               being updated. You may want to take the turbo
  46.               button off for a while to see what speed it
  47.               runs at. */
  48.  for (i = 0; i < 200; i++)
  49.     shadedline (0, 0, 319 - i, col, i);
  50.  
  51.  } while (!kbhit ());
  52.  
  53.  getch ();
  54.  setvideomode (3);
  55.  
  56. }